package com.jswlw.controller.distributor;

import com.jswlw.controller.BaseController;
import com.jswlw.entity.biz.BookInfo;
import com.jswlw.entity.biz.RepairInfo;
import com.jswlw.service.biz.RepairInfoService;
import com.jswlw.web.manager.SessionDistributorManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 吴维斌 E-mail:wuweibin0817@163.com
 * @version 创建时间：${date} ${time}
 */
@Controller
@RequestMapping("/distributor/repair")
public class DistributorRepairController extends BaseController{

    @Autowired
    RepairInfoService repairInfoService;

    @RequestMapping("index")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/distributor/repair/index");
        RepairInfo filter = new RepairInfo();
        filter.setDistributorIds(SessionDistributorManager.getCurrentUser().getChildrenIds());

        modelAndView.addObject("repairList", repairInfoService.queryList(filter));
        return modelAndView;
    }

    @RequestMapping("/deal")
    @ResponseBody
    public ModelMap deal(Model model, Integer id) {
        try {
            RepairInfo repairInfo = new RepairInfo();
            repairInfo.setId(id);
            repairInfo.setStatus(1);
            repairInfoService.update(repairInfo);
            return this.successResult("处理成功");
        } catch (Exception e) {
            logger.error("处理失败", e);
            return this.failResult("处理失败" + e.getMessage());
        }
    }
}
